package cn.edu.jxau.core.controller;

import java.util.Map;

import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SessionListener implements HttpSessionListener{
    private static Logger logger = LoggerFactory.getLogger(SessionListener.class);
    
    @Override
    public void sessionCreated(HttpSessionEvent se) {
    }
    
    @Override
    public void sessionDestroyed(HttpSessionEvent se) {
      //在session销毁的时候 把loginMap中保存的键值对清除
        Integer userID = (Integer) se.getSession().getAttribute("userID");
        if(userID != null) {
            Map<String, String> loginMap = (Map<String, String>) se.getSession().getServletContext().getAttribute("loginMap");
            loginMap.remove(userID);
            se.getSession().getServletContext().setAttribute("loginMap", loginMap);
            logger.debug(userID + "用户注销！");
        }
    }
}
